import { nextTick } from 'vue'
import { useMemberStore } from '@/stores'

export function useHiddenTitle() {
  // #ifdef H5
  console.log('isH5')
  const ua = navigator.userAgent.toLowerCase()

  const isWeiXinBrowser = () => {
    //判断是否为微信
    const ua = navigator.userAgent.toLowerCase()
    return ua.indexOf('micromessenger') != -1
  }
  if (isWeiXinBrowser()) {
    // 在微信浏览器内屏蔽掉多余的标题
    console.log('isWeiXinBrowser')
    nextTick(() => {
      const navTitleDom = document.getElementsByTagName('uni-page-head')
      if (navTitleDom.length) {
        ;(navTitleDom[0] as HTMLLIElement).style.display = 'none'
        ;(navTitleDom[0] as HTMLLIElement).style.height = '0px'
        // 补充高度 主要是看有没有标题
        const systemInfo = uni.getSystemInfoSync()
        const uniPageWrapper = document.getElementsByTagName('uni-page-wrapper')[0]
        // 标题栏是一定有的 要减去
        if (systemInfo.windowTop > 0) {
          uniPageWrapper.classList.add('addHeaderHeight')
        } else {
          uniPageWrapper.classList.remove('addHeaderHeight')
        }
        // tabbar栏 不一定有 如果有 就减去
        if (systemInfo.windowTop > 0 && systemInfo.windowBottom == 0) {
          uniPageWrapper.classList.add('addHeaderAndBottomHeight')
        } else {
          uniPageWrapper.classList.remove('addHeaderAndBottomHeight')
        }
      }
    }).then((r) => {})
  }
  // #endif
}

export function useCheckIsLogin() {
  const memberStore = useMemberStore()

  if (!memberStore.profile) {
    // 获得当前页 当前页不在白名单中且不包含/login路径 则跳转到登录页
  }
}
